<template>
  <div class="forget-password-container">
    <el-card class="forget-password-card">
      <h2 class="title">忘记密码</h2>
      
      <!-- 角色选择 -->
      <el-radio-group v-model="userRole" class="role-group">
        <el-radio label="student">学生</el-radio>
        <el-radio label="counselor">辅导员</el-radio>
        <el-radio label="enterprise">企业</el-radio>
      </el-radio-group>

      <el-form 
        :model="formData" 
        :rules="rules" 
        ref="forgetForm" 
        label-width="100px"
        class="forget-form"
      >
        <!-- 账号 -->
        <el-form-item label="账号" prop="account">
          <el-input v-model="formData.account" placeholder="请输入账号"></el-input>
        </el-form-item>

        <!-- 姓名/企业名称 -->
        <el-form-item 
          :label="userRole === 'enterprise' ? '企业名称' : '姓名'" 
          prop="name"
        >
          <el-input v-model="formData.name" :placeholder="userRole === 'enterprise' ? '请输入企业名称' : '请输入姓名'"></el-input>
        </el-form-item>

        <!-- 学号/教职工号 (仅学生和辅导员显示) -->
        <el-form-item 
          v-if="userRole !== 'enterprise'"
          :label="userRole === 'student' ? '学号' : '教职工号'"
          prop="number"
        >
          <el-input 
            v-model="formData.number"
            :placeholder="userRole === 'student' ? '请输入学号' : '请输入教职工号'"
          ></el-input>
        </el-form-item>

        <!-- 新密码 -->
        <el-form-item label="新密码" prop="newPassword">
          <el-input 
            v-model="formData.newPassword" 
            type="password"
            placeholder="请输入新密码"
          ></el-input>
        </el-form-item>

        <!-- 确认密码 -->
        <el-form-item label="确认密码" prop="confirmPassword">
          <el-input 
            v-model="formData.confirmPassword" 
            type="password"
            placeholder="请再次输入新密码"
          ></el-input>
        </el-form-item>

        <!-- 提交按钮 -->
        <el-form-item>
          <el-button type="primary" @click="submitForm">重置密码</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'ForgetPassword',
  data() {
    // 密码确认验证
    const validateConfirmPassword = (rule, value, callback) => {
      if (value !== this.formData.newPassword) {
        callback(new Error('两次输入的密码不一致'));
      } else {
        callback();
      }
    };

    return {
      userRole: 'student', // 默认选中学生角色
      formData: {
        account: '',
        name: '',
        number: '',
        newPassword: '',
        confirmPassword: ''
      },
      rules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        number: [
          { required: true, message: '请输入编号', trigger: 'blur' }
        ],
        newPassword: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ],
        confirmPassword: [
          { required: true, message: '请确认密码', trigger: 'blur' },
          { validator: validateConfirmPassword, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.forgetForm.validate((valid) => {
        if (valid) {
          // TODO: 调用重置密码API
          console.log('表单提交', this.formData);
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.forget-password-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.forget-password-card {
  width: 500px;
  padding: 20px;
}

.title {
  text-align: center;
  margin-bottom: 30px;
  color: #303133;
}

.role-group {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.forget-form {
  margin-top: 20px;
}

.el-button {
  width: 100%;
}
</style>
